<template>
  <div class="login-container">
    <!-- 背景图案 -->
    <div class="background-pattern"></div>

    <!-- 登录表单 -->
    <div class="login-form-wrapper">
      <h2 class="custom-title">上下游犯罪漏犯漏罪法律监督大模型平台</h2>
      <p class="custom-subtitle">可视化平台</p>

      <!-- 用户名输入框 -->
      <el-form :model="loginForm" status-icon :rules="rules" ref="loginFormRef" >
        <el-form-item prop="username">
          <div class="custom-input-label">用户名</div>
          <el-input v-model="loginForm.username" placeholder="请输入用户名" class="transparent-input"></el-input>
        </el-form-item>

        <!-- 密码输入框 -->
        <el-form-item prop="password" >
          <div class="custom-input-label">密码</div>
          <el-input type="password" v-model="loginForm.password" placeholder="请输入密码" show-password class="transparent-input"></el-input>
        </el-form-item>

        <!-- 登录按钮 -->
        <el-form-item>
          <el-button type="primary" style="width: 100%;" @click="submitForm('loginFormRef')">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 验证用户名和密码
          if (this.loginForm.username === 'admin' && this.loginForm.password === '12345678') {
            // 验证通过
            this.$message({
              message: '登录成功',
              type: 'success'
            });
            // 模拟登录延迟
            setTimeout(() => {
              this.$router.push({ name: 'GeneralView' });
            }, 1000);
          } else {
            // 验证失败，使用全局消息提示
            this.$message({
              message: '用户名或密码错误',
              type: 'error'
            });
          }
        } else {
          console.log('表单验证失败');
          return false;
        }
      });
    }
  }
};
</script>
<style scoped>
.login-container {
  display: flex;
  justify-content: flex-end; /* 将内容对齐到右侧 */
  align-items: center;
  height: 100vh;
  background-size: cover;
  background-position: center;
  background-image: url('@/assets/background.png');
  padding-right: 5vh;
}

.login-form-wrapper {
  width: 50%;
  padding: 2vh 2vw;
  box-sizing: border-box;
  border-radius: 1vh;
}

.custom-title{
  text-align: center;
  font-size: 4vh;
  color:#6ba3e6;
}

.custom-subtitle{
  text-align: center;
  font-size: 3vh;
  color:#6ba3e6;
}

.custom-input-label {
  font-size: 2vh;
  color: #6ba3e6;
  margin-bottom: 1vh;
}

.el-form-item {
  width: 100%;
  margin-bottom: 1vh;
}

/deep/ .transparent-input .el-input__inner {
  height: 5vh;
  line-height: 1.5vh;
  font-size: 2vh;
}

.el-button {
  margin-top: 5vh;
  height: 5vh;
  width: 100%;
}
</style>
